package com.ruoyi.mall.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.entity.MallAddress;



import com.ruoyi.mall.service.IMallAddressService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 会员地址Controller
 * 
 * @author ruoyi
 * @date 2020-05-16
 */
@RestController
@RequestMapping("/mall/address")
public class MallAddressController extends BaseController
{
    String prefix = "mall/address";
    @Autowired
    private IMallAddressService mallAddressService;
    @RequiresPermissions("mall:address:view")
    @GetMapping()
    public String address()
    {
       
        return prefix + "/address";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("mall:address:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallAddress mallAddress)
    {
        startPage();
        List<MallAddress> list = mallAddressService.selectMallAddressList(mallAddress);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @RequiresPermissions("mall:category:export")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallAddress MallAddress) {
        List<MallAddress> list = mallAddressService.selectMallAddressList(MallAddress);
        ExcelUtil<MallAddress> util = new ExcelUtil<MallAddress>(MallAddress.class);
        return util.exportExcel(list, "category");
    }
    /**
     * 新增商品分类
     */
    @GetMapping("/add")
    public String add( ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave( @RequestBody MallAddress mallAddress)
    {
        return toAjax(mallAddressService.insertMallAddress(mallAddress));
    }


    /**
     * 修改会员地址
     */
    @GetMapping("/edit/{addressId}")
    public AjaxResult edit(Long addressId)
    {
        MallAddress mallAddress = mallAddressService.selectMallAddressById(addressId);
        return AjaxResult.success(mallAddress);
    }

    /**
     * 修改保存会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallAddress mallAddress)
    {
        return toAjax(mallAddressService.updateMallAddress(mallAddress));
    }

    /**
     * 删除会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallAddressService.deleteMallAddressByIds(ids));
    }
}
